package cn.arikeky.tran;

import org.apache.rocketmq.client.producer.LocalTransactionState;
import org.apache.rocketmq.client.producer.TransactionListener;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;

public class TranListener implements TransactionListener {

    /**
     * 事务方法在这里执行mapper 返回是否成功执行事务
     * @param message
     * @param org
     * @return
     */
    @Override
    public LocalTransactionState executeLocalTransaction(Message message, Object org) {
        try {
            System.out.println("事务已经成功执行了");
            return LocalTransactionState.COMMIT_MESSAGE;
        } catch (Exception e) {
            e.printStackTrace();
            return LocalTransactionState.ROLLBACK_MESSAGE;
        }
    }

    @Override
    public LocalTransactionState checkLocalTransaction(MessageExt messageExt) {
        try {
            System.out.println("事务已经执行完成了");
            return LocalTransactionState.COMMIT_MESSAGE;
        } catch (Exception e) {
            e.printStackTrace();
            return LocalTransactionState.ROLLBACK_MESSAGE;
        }
    }
}
